package cn.ijero.pictureselector;

import android.content.Context;
import android.content.Intent;

import java.lang.ref.WeakReference;

import cn.ijero.pictureselector.callback.PictureSelectorCallback;
import cn.ijero.pictureselector.config.PictureSelectorConfig;
import cn.ijero.pictureselector.delegate.PictureSelectorActivity;

public class PictureSelector {

    private static WeakReference<Context> mContext;

    private PictureSelector(Context context) {
        if (mContext == null) {
            mContext = new WeakReference<>(context);
        }
    }

    /**
     * 初始化相册选择
     *
     * @param context Activity对象
     * @return
     */
    public static PictureSelector with(Context context) {
        return new PictureSelector(context);
    }

    /**
     * 加载相册照片
     *
     * @param callback 选择相册回调
     */
    public void load(PictureSelectorCallback callback) {
        PictureSelectorConfig.callback = callback;
        Context context = mContext.get();
        if (context != null) {
            Intent intent = new Intent(context, PictureSelectorActivity.class);
            context.startActivity(intent);
        }
    }

}
